package com.sleepfish.activiti.controller;

import com.sleepfish.activiti.domain.VO.process.BpmProcessDefinitionListReqVO;
import com.sleepfish.activiti.domain.VO.process.BpmProcessDefinitionPageReqVO;
import com.sleepfish.activiti.domain.VO.process.BpmProcessDefinitionRespVO;
import com.sleepfish.activiti.service.IBpmProcessDefinitionService;

import com.sleepfish.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * Bpm 流程定义的拓展表
 前端控制器
 * </p>
 *
 * @author xiaochao
 * @since 2022-03-12
 */
@Api(tags = "流程定义")
@RestController
@RequestMapping("/bpm/process-definition")
public class BpmProcessDefinitionController {

    @Autowired
    private IBpmProcessDefinitionService bpmDefinitionService;

    @GetMapping("/page")
    @ApiOperation(value = "获得流程定义分页")
    //@PreAuthorize("@ss.hasPermi('bpm:process-definition:query')")
    public AjaxResult getProcessDefinitionPage(
            BpmProcessDefinitionPageReqVO pageReqVO) {
        return AjaxResult.success(bpmDefinitionService.getProcessDefinitionPage(pageReqVO));
    }

    @GetMapping("/list/pro")
    @ApiOperation(value = "获得流程定义列表扩展")
    //@PreAuthorize("@ss.hasPermi('bpm:process-definition:query')")
    public AjaxResult getProcessDefinitionListPro(
            BpmProcessDefinitionPageReqVO pageReqVO) {
        //pageReqVO.setPageSize(100000);
        return AjaxResult.success(bpmDefinitionService.getProcessDefinitionPage(pageReqVO));
    }

    @GetMapping ("/list")
    @ApiOperation(value = "获得流程定义列表")
    //@PreAuthorize("@ss.hasPermi('bpm:process-definition:query')")
    public AjaxResult getProcessDefinitionList(
            BpmProcessDefinitionListReqVO listReqVO) {
        return AjaxResult.success(bpmDefinitionService.getProcessDefinitionList(listReqVO));
    }

    @GetMapping ("/get-bpmn-xml")
    @ApiOperation(value = "获得流程定义的 BPMN XML")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    //@PreAuthorize("@ss.hasPermi('bpm:process-definition:query')")
    public AjaxResult getProcessDefinitionBpmnXML(@RequestParam("id") String id) {
        String bpmnXML = bpmDefinitionService.getProcessDefinitionBpmnXML(id);
        System.out.println("bpmnXML");
        System.out.println(bpmnXML);
        return AjaxResult.success(bpmnXML);
    }




}
